import xlwings as xw

# 获取当前文件夹路径
def get_path():
    import os
    return os.path.dirname(os.path.abspath(__file__))


def creat_excel_file(filename, num):
  app = xw.App(visible=True, add_book=False)
  path = get_path()  # 获取当前文件夹路径
  print(path)
  for i in range(1, num+1):
    workbook = app.books.add()
    workbook.save(f'{path}\\{filename}{i}.xlsx')
    workbook.close()
  app.quit()


# python 01\excel_primer_demo.py
if __name__ == '__main__':
  creat_excel_file('test', 1)
  # # 打开Excel
  # app = xw.App(visible = True, add_book = False)
  # # 循环打开分公司员工信息表
  # for i in range(1, 21):
  #     # 打开分公司员工信息表
  #     workbook = app.books.open(f'{path}\\员工信息表\\分公司{i}.xlsx')
  #     # 获取第一个工作表
  #     worksheet = workbook.sheets[0]
  #     # 获取第一行的值
  #     values = worksheet.range('A1').expand('down').value
  #     # 获取第一行的最大行数
  #     max_row = len(values)
  #     # 获取第一行的最大列数
  #     max_column = len(values[0])
  #     # 获取第一行的最大行数和最大列数
  #     max_row, max_column = worksheet.range('A1').expand('table').shape
  #     # 获取第一行的最大行数和最大列数
  #     max_row, max_column = worksheet.used_range.shape
  #     # 获取第一行的最大行数和最大列数
  #     max_row, max_column = worksheet.api.UsedRange.Rows.Count, worksheet.api.UsedRange.Columns.Count
  #     # 获取第一行的最大行数和最大列数
  #     max_row, max_column = worksheet.api.UsedRange.Cells.SpecialCells(11).Row, worksheet.api.UsedRange.Cells.SpecialCells(11).Column
  #     # 获取第一行的最大行数和最大列数
  #     max_row, max_column = worksheet.api.UsedRange.Cells.SpecialCells(12).Row, worksheet.api.UsedRange.Cells.SpecialCells(12).Column
  #     # 获取第一行的最大行数和最大列数
  #     max_row, max_column = worksheet.api.UsedRange.Cells.SpecialCells(11).Row, worksheet.api.UsedRange.Cells.SpecialCells(11).Column
  #     # 获取第一行的最大行数和最大列数
  #     max_row, max_column = worksheet.api.UsedRange.Cells.SpecialCells(12).Row, worksheet.api.UsedRange.Cells.SpecialCells(12).Column
  #     # 获取第一行的最大行数
